#include<stdio.h>
#include<malloc.h>

void quick_sort(int* a,int n){
    if (n == 0 || n == 1)return;
    int i,j,k,tmp,cur;
    cur = a[0]; i = 0; j = n-1;
    while(i!=j){
        if( (i<j && a[i]>a[j]) || (i>j && a[i]<a[j]) ){
            tmp = a[i];a[i]=a[j];a[j]=tmp;
            tmp = i; i = j; j = tmp;
        }
        if(i<j)--j;else ++j;
    }
    quick_sort(a,i);
    quick_sort(a+i+1,n-i-1);
}


int main(int argc,char** argv){
    int NUM_SIZE = 0; int i;
    printf("Enter Element Count: ");
    scanf("%d",&NUM_SIZE);
    printf("Enter Elements seperated with white spaces:\n");
    int* quick = malloc(sizeof(int)*NUM_SIZE);
    for(i=0;i<NUM_SIZE;i++)scanf("%d",quick+i);
    quick_sort(quick,NUM_SIZE);
    for(i=0;i<NUM_SIZE;i++)printf("%d ",quick[i]);putchar('\n');
    return 0;
}
